<?php
session_start();

include_once( 'config.php' );
include_once( 'saetv2.ex.class.php' );

$o = new SaeTOAuthV2( WB_AKEY , WB_SKEY );

if (isset($_REQUEST['code'])) {
	$keys = array();
	$keys['code'] = $_REQUEST['code'];
	$keys['redirect_uri'] = WB_CALLBACK_URL;
	try {
		$token = $o->getAccessToken( 'code', $keys ) ;
	} catch (OAuthException $e) {
	}
}
//[access_token] => 2.00LwtHQDJ821EEc50258dbf00g8N2P [remind_in] => 105834 [expires_in] => 105834 [uid] => 2986703195
if ($token) {
	$_SESSION['token'] = $token;
	setcookie( 'weibojs_'.$o->client_id, http_build_query($token) );
			} else {
?>
授权失败。
<?php
}
//获取用户信息
$c = new SaeTClientV2( WB_AKEY , WB_SKEY , $_SESSION['token']['access_token'] );
$uid = $_SESSION['token']['uid'];
$user_message = $c->show_user_by_id( $uid);//根据ID获取用户等基本信息
//print_r($user_message);
echo $user_message['screen_name'];
echo "<img style='margin:3px;float:left' width='25px' height='25px' src=".$user_message['avatar_large']." alt="" />";
echo $user_message['profile_image_url'];
//screen_name 	string 	用户昵称
//profile_image_url 	string 	用户头像地址，50×50像素 
//profile_url 	string 	用户的微博统一URL地址 （短的）！前加www.weibo.com/
//gender 	string 	性别，m：男、f：女、n：未知 
//avatar_large 	string 	用户大头像地址
echo "session的值：<br/>";
print_r($_SESSION);
//echo "<script>location.href='www.kuaipaila.com/index.php'</script>";
?>
